package com.shenzhen.horselive.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.shenzhen.horselive.R;
import com.shenzhen.horselive.User;
import com.shenzhen.horselive.adapter.MyActionHallAdapter;
import com.shenzhen.horselive.adapter.MyCityAdapter;
import com.shenzhen.horselive.api.ApiFactory;
import com.shenzhen.horselive.base.AppBarActivity;
import com.shenzhen.horselive.beans.MyCityBean;
import com.shenzhen.horselive.databinding.ActivityMyCityBinding;
import com.shenzhen.horselive.network.SchedulersCompat;
import com.shenzhen.horselive.presenter.LoadingViewObserver;

public class MyAuctionHallActivity extends AppBarActivity {

    ActivityMyCityBinding  binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMyCityBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        setStyleDark();
        setTitle("我的参与的竞拍");
        initViews();
//        initData();
    }
    @Override
    protected void onResume() {
        super.onResume();
        initData();
    }
    private void initData() {
        ApiFactory.getApiService().myactionlist(User.get().getMyInfo().getToken())
                .compose(SchedulersCompat.applyIoSchedulers())
                .safeSubscribe(new LoadingViewObserver<MyCityBean>(this) {
                    @Override
                    protected void onNextInActive(MyCityBean myCityBean) {
                        if (myCityBean.isSuccess())
                        {
                            myCityAdapter.setNewInstance(myCityBean.getData());
                        }else
                        {
                            showToast(myCityBean.getErrMessage());
                        }
                    }
                });
    }

    MyActionHallAdapter myCityAdapter;
    private void initViews() {
        binding.recyclerview.setLayoutManager(new LinearLayoutManager(this));
        myCityAdapter =  new MyActionHallAdapter(R.layout.item_my_city);
        binding.recyclerview.setAdapter(myCityAdapter);
        myCityAdapter.setEmptyView(R.layout.no_data_layout);
        binding.btAuctionHall.setVisibility(View.GONE);
      //点击事件
      myCityAdapter.setOnItemClickListener(new OnItemClickListener() {
          @Override
          public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
              MyCityBean.DataBean  dataBean= myCityAdapter.getItem(position);
              if (dataBean.getStatus()==1)
              {
                  //竞拍中
                  AuctionDetailsActivity.start(getContext(),dataBean.getAreaCode());
              }else {
                  //已经结束
              }
          }
      });

    }

}